package com.demo.swingquickticket.swing.view.account;

import com.demo.swingquickticket.service.AccountService;
import com.demo.swingquickticket.swing.layoutUtil.GBC;
import com.demo.swingquickticket.swing.view.account.user.UserDetailPanel;
import com.demo.swingquickticket.util.SpringUtils;

import javax.swing.*;
import java.awt.*;

public class AccountPanel extends JPanel {

    private AccountService accountService = SpringUtils.getBean("accountService");

    private JButton checkLoginBtn;
    private JButton userDetail;
    private JLabel title;
    private JPanel functionPanel;

    public AccountPanel() {
        init();
        bind();
    }

    private void init() {
        this.setLayout(new GridBagLayout());
        GBC gbc = GBC.getInstance().setInsets(new Insets(5,5,5,5));

        gbc.setFill(GBC.BOTH).setGridXY(0,0).setGridWH(2,1).setWeightXY(20, 10);
        checkLoginBtn = new JButton("检测状态");
        this.add(checkLoginBtn, gbc);

        gbc.setGridXY(0,1);
        userDetail = new JButton("个人信息");
        this.add(userDetail, gbc);

        gbc.setGridXY(0,2).setGridWH(2, 8).setWeightXY(20, 80);
        JLabel empty = new JLabel();
        this.add(empty, gbc);

        gbc.setFill(GBC.NONE).setAnchor(GBC.CENTER).setGridXY(2, 0).setGridWH(8, 1).setWeightXY(80, 10);
        title = new JLabel("这是标题");
        this.add(title, gbc);

        gbc.setFill(GBC.BOTH).setGridXY(2, 1).setGridWH(8, 9).setWeightXY(80, 90);
        functionPanel = new JPanel(new BorderLayout());
        functionPanel.add(UserDetailPanel.getInstance(), BorderLayout.CENTER);
        this.add(functionPanel, gbc);
    }

    private void bind() {
        checkLoginBtn.addActionListener(e -> {
            String result = accountService.checkLogin();
            JOptionPane.showMessageDialog(this, result);
        });
    }
}
